Step 40: Deploy

Let's deploy the Bookmark API to Heroku.

  1. Head over to Heroku and create a new app. I called my app bookmark-api-fsjs.

  2. In Settings, Add "Nodejs" as a "Buildpack."

  3. In Settings, click on Reveal “Config Vars” and add DB_URL (with its value for your app that points to the MongoDB cluster you’ve created in the cloud.) Note you should not wrap the connection URI in double quotations. You may also want to change the database name to something like “prod” (for production).

  4. Update const ****PORT = 3000; in server.js to const PORT = process.env.PORT || 3000;

  5. Add a Procfile to the project root folder:

    web: yarn start
    
  6. Next, create a .github folder. Add a subfolder workflows to .github. Finally, add a deploy.yml file to this subfolder with the following content:

    name: Deploy the server (backend) app
    
    on:
      push:
        branches:
          - main
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - uses: akhileshns/heroku-deploy@v3.12.12
            with:
              heroku_api_key: ${{secrets.HEROKU_AUTH_TOKEN}}
              heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
              heroku_email: ${{secrets.HEROKU_AUTH_EMAIL}}
    
  7. Create a GitHub repository for this project. Go to the GitHub repository for this project and select the “Settings” tab. Then, under the “Security” heading, open “Secrets” and select “Actions.” Finally, add the secrets that your deploy.yml depends on.

  8. Push your code to the GitHub repository and watch GitHub Action deploy your app to Heroku!